// 拦截器类型
export interface Interceptor<V> {
  onFulfilled?: (value: V) => V | Promise<V>;
  onRejected?: (error: any) => any;
}

// 请求配置
export interface RequestConfig {
  url?: string;
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
  headers?: Record<string, string>;
  body?: any;
  _retrying?: boolean;
  signal?: AbortSignal;
  [key: string]: any;
}

// 响应结构
export interface Response<T = any> {
  data: T;
  status: number;
  statusText: string;
  headers: Headers;
  config: RequestConfig;
}

// 缓存项
export interface CacheItem {
  data: any;
  timestamp: number;
  ttl: number;
}
export interface RequestOptions extends RequestInit {
  params?: Record<string, any>;
  cacheKey?: string;
  cacheTTL?: number;
  maxRetry?: number;
  retryDelay?: number;
  skipAuth?: boolean;
}

export interface ResponseData<T = any> {
  code: number;
  message: string;
  data: T;
}

export interface AuthToken {
  accessToken: string;
  refreshToken: string;
  expiresIn: number;
}
export interface RequestInterceptor extends Interceptor<RequestConfig> {
  onFulfilled?: (value: RequestConfig) => RequestConfig | Promise<RequestConfig>;
  onRejected?: (error: any) => any;
}

export interface ResponseInterceptor extends Interceptor<Response> {
  onFulfilled?: (value: Response) => Response | Promise<Response>;
  onRejected?: (error: any) => any;
}